package com.poi.tl.sample.quickstart.app.tags;

import com.deepoove.poi.XWPFTemplate;
import com.poi.tl.sample.quickstart.consts.AppConsts;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.springframework.core.io.ClassPathResource;

public class _6_2SectionObjectExport {

  public static void main(String[] args) throws Exception {
    ClassPathResource templateFile = new ClassPathResource(AppConsts.TAG_TEMPLATE_CLASS_PATH + "_6_2section_object_template.docx");
    String outFile = AppConsts.EXPORT_PATH + "_6_2section_object_template_output.docx";

    // 1 	compile 编译模板
    XWPFTemplate template = XWPFTemplate.compile(templateFile.getInputStream()).render(
        // 2 render 渲染数据
        new HashMap<String, Object>(){{
          Map<String, String> person = new HashMap<>();
          person.put("name", "Sayi 6_2");
          put("person", person);
        }});
    // 3 write 输出到流
    template.writeAndClose(new FileOutputStream(outFile));
  }

}
